﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Remoting;
using System.Text;

namespace QQCommServer
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //RemotingConfiguration.Configure("QQCommServer.exe.config");
            //Console.WriteLine("Listening for requests. Press Enter to exit");
            //Console.ReadLine();

            //RemotingConfiguration.Configure("QQCommServer.exe.config");
            //RemotableType remoteObject = new RemotableType();
            //Console.WriteLine(remoteObject.StringMethod());


            //try
            //{
            int port = 2000;
            string host = "127.0.0.1";
            IPAddress ip = IPAddress.Parse(host);
            IPEndPoint ipe = new IPEndPoint(ip, port);
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            s.Bind(ipe);
            s.Listen(0);
            Socket temp = s.Accept();
            string recvStr = "";
            byte[] recvBytes = new byte[1024];
            int bytes;
            bytes = temp.Receive(recvBytes, recvBytes.Length, 0);
            recvStr += Encoding.ASCII.GetString(recvBytes, 0, bytes);
            Console.WriteLine(recvStr);
            string sendStr = "Ok!Sucess!";
            byte[] bs = Encoding.ASCII.GetBytes(sendStr);
            temp.Send(bs, bs.Length, 0);
            temp.Shutdown(SocketShutdown.Both);
            temp.Close();
            s.Shutdown(SocketShutdown.Both);
            s.Close();
            //}
            //catch (ArgumentNullException e)
            //{
            //    Console.WriteLine("ArgumentNullException: {0}", e);
            //}
            //catch (SocketException e)
            //{
            //    Console.WriteLine("SocketException: {0}", e);
            //}
            Console.ReadLine();
        }
    }
}

